package com.dyzs.util;

import java.util.Iterator;
import java.util.Map;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;



public class WSUtils {

//	public static String callWS(String methodName, Map params,String serviceClass) throws Exception {
//		SoapObject rpc = new SoapObject(Constants.NAMESPACE, methodName);
//		if (params != null && !params.isEmpty()) {			
//			for (Iterator it = params.entrySet().iterator(); it.hasNext();) {
//				Map.Entry<String, Object> e = (Map.Entry<String, Object>) it.next();			
//				rpc.addProperty(e.getKey().toString().trim(), e.getValue());
//			}
//		}
//		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//
//		envelope.bodyOut = rpc;
//		envelope.dotNet = false; 
//		HttpTransportSE he=new HttpTransportSE(serviceClass,15000);
////		AndroidHttpTransport ht = new AndroidHttpTransport(serviceClass);
//		try {
//			he.call("", envelope);			
//		}catch (Exception e) {			
//			System.out.println("e2="+e.getMessage());
//			e.printStackTrace();
//			throw new Exception("网络异常，请重试！");
//		}
//		Object result = envelope.getResponse();		
//		String str = result.toString();
//		return str;
//	}
	
	
	public static String callWS(String methodName, Map params,String serviceClass) throws Exception {
		SoapObject rpc = new SoapObject("http://server.mobile.dyzs.gsww.com/", methodName);
		if (params != null && !params.isEmpty()) {			
			for (Iterator it = params.entrySet().iterator(); it.hasNext();) {
				Map.Entry<String, Object> e = (Map.Entry<String, Object>) it.next();			
				rpc.addProperty(e.getKey().toString().trim(), e.getValue());
			}
		}
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

		envelope.bodyOut = rpc;
		envelope.dotNet = false; 
		HttpTransportSE he=new HttpTransportSE(serviceClass,15000);
//		AndroidHttpTransport ht = new AndroidHttpTransport(serviceClass);
		try {
			he.call("", envelope);			
		}catch (Exception e) {			
			System.out.println("e2="+e.getMessage());
			e.printStackTrace();
			throw new Exception("网络异常，请重试！");
		}
		Object result = envelope.getResponse();		
		String str = result.toString();
		return str;
	}
		
	
	
	
}
